import {createSlice} from "@reduxjs/toolkit";

const channelStore = createSlice({
    name: 'channel',
    initialState: {
        channelList: []
    },
    reducers: {
        setChannelList(state, action) {
            console.log(state.channelList,'数据')
            console.log(state,'state')
            console.log(action,'action')
            state.channelList = action.payload
        }
    }
})
const {setChannelList} = channelStore.actions
//异步请求方式
const fechChannelList = () => {
    return async (dispatch) => {
        const list = [
            {
                name: "react1",
                id: 1
            },
            {
                name: "react2",
                id: 2
            },
            {
                name: "react3",
                id: 3
            },
            {
                name: "react4",
                id: 4
            }
        ]
        dispatch(setChannelList(list))
        //异步请求
    }
}
export {fechChannelList}
const reducer = channelStore.reducer
export default reducer
